package 多线程.复习.线程方法;

public class JoinOfThread {
    private static class JoinMethod implements Runnable{
        int num = 0;
        @Override
        public void run() {
            for (int i = 0; i < 3; i++) {
                System.out.println("子线程占用资源");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new JoinMethod(),"子线程");
        thread.start();
//        thread.join();//在主线程中调用子线程的join方法，就会让主线程进入阻塞状态，直到子线程执行结束，才会开始主线程
        for (int i = 0; i < 3; i++) {
            System.out.println("主线程占用资源");
            Thread.sleep(1000);
        }
    }
}
